home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / midipeek.zip / MPU.PAS < prev    next >
Pascal/Delphi Source File  |  1988-09-04  |  2KB  |  96 lines

  1. { Copyright 1986, 1987, 1988 Carter Scholz}
  2.  
  3. unit MPU;
  4.  
  5. interface
  6.  
  7. uses Crt;
  8.  
  9.   procedure PutData (MidiData:byte);      { Puts one byte to MPU. }
  10.   procedure GetData (var MidiData:byte);  { Gets one byte from MPU. }
  11.   procedure PutCmd (cmd:byte);            { Sends command to MPU. }
  12.   procedure ResetMPU;              { Resets MPU to power-up state. }
  13.  
  14. const
  15.   dataport=$330;       { These are port addresses for the }
  16.   statport=$331;       { IBM version of the MPU-401.      }
  17.   drs=$80;             { They must be changed for other   }
  18.   drr=$40;             { machines.                        }
  19.   ack=$fe;
  20.   TooLong=$4000;       { timeout value }
  21.  
  22. var
  23.   MPUdone, TimeOut : boolean;
  24.  
  25. implementation
  26.  
  27. procedure PutData (MidiData:byte);      { Puts one byte to MPU. }
  28.   var
  29.     j: byte;
  30.     k: word;
  31.   begin
  32.     j := 0; k:=0;
  33.     TimeOut:=false;
  34.     repeat
  35.       j := port [statport];
  36.       if (j and drs)=0 then k:=port[dataport];
  37.       inc(k);
  38.       if k>TooLong then Timeout:=true;
  39.     until ((j and drr)=0) or Timeout;
  40.     port [dataport] := MidiData;
  41.   end;
  42.  
  43. procedure GetData (var MidiData:byte);  { Gets one byte from MPU. }
  44.   var
  45.     j: byte;
  46.     k: word;
  47.   begin
  48.     j := 0; k:=0;
  49.     Timeout:=false;
  50.     repeat
  51.       inc(k);
  52.       j := port [statport];
  53.       if k>=TooLong then TimeOut:=true;
  54.       if keypressed then halt;
  55.     until ((j and drs)=0) or TimeOut;
  56.     MidiData := port [dataport];
  57.   end;
  58.  
  59. procedure PutCmd (cmd:byte);            { Sends command to MPU. }
  60.   var
  61.     j: byte;
  62.     k: word;
  63.   begin
  64.     j := 0; k:=0;
  65.     TimeOut := false;
  66.     repeat
  67.       k:=succ(k);
  68.       j := port [statport];
  69.       if k>TooLong then
  70.         Timeout:=true;
  71.     until ((j and drr)=0) or Timeout;
  72.     port [statport] := cmd;
  73.     k:=0;
  74.     repeat
  75.       inc(k);
  76.       GetData(j);
  77.       if k>TooLong then Timeout:=true;
  78.     until (j=ack) or Timeout;
  79.   end;
  80.  
  81. procedure ResetMPU;              { Resets MPU to power-up state. }
  82.   var
  83.     j: byte;
  84.     k: word;
  85.   begin
  86.     k:=0; Timeout:=false;
  87.     repeat
  88.       j := port [statport];
  89.       if (j and drr) = 0 then port [statport] := $ff;
  90.       j := port [dataport];
  91.       inc(k);
  92.       if k>TooLong then Timeout:=true;
  93.     until (j=ack) or Timeout;
  94.   end;
  95.  
  96. end.